// Xml_Http.h: interface for the CXml_Http class.
//
//////////////////////////////////////////////////////////////////////

#ifndef __AOT_XML_HTTP_H__ 
#define __AOT_XML_HTTP_H__



#include <atlbase.h>
#include <comdef.h>
#include <string>

#import "./msxml6.dll" 

class CXml_Http  
{
#define _IS_VALID(x) do{if(!is_valid()) return (x);}while(0)
public:
	bool append_header(const char* pszName, const char* pszVal);
	bool open(const char* pszUrl, const char* pszMethod = "POST", const char* pszUser = NULL, const char* pszPwd = NULL);
	bool send_str(const char* pszData = NULL);
	bool send_bin(const char *pszData = NULL, size_t nLen = 0);
    bool recv(std::string &strData, const char *charsetName = "UTF-8");
	

	bool is_valid();

	bool close(){return true;}
	const char* get_err_msg(){return m_szErr;}
	inline void set_err_msg(const char* p)
	{
		try
		{
			strcpy(m_szErr, p);
		}
		catch(...)
		{
			;
		}
	}
	
	CXml_Http();
	virtual ~CXml_Http();

private:
	bool __init();
	void __release();
	static bool __to_variant(const char* pBuffer,VARIANT* vt, long len);
	inline void __ser_no_err() {m_szErr[0] = 0;}
private:
	char m_szErr[256];
    
    MSXML2::IServerXMLHTTPRequestPtr m_req_ptr;
	//MSXML2::IXMLHTTPRequestPtr m_req_ptr;
	bool m_bValid;
};

#endif // __AOT_XML_HTTP_H__
